<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page session="false" %>
<%@ page isELIgnored ="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
			<script type="text/javascript">
				require(["dojo/on"],function(on){
					$kdom.appendDojoProp("btn_org_refresh","label",KppModule.commonResource.refresh);
				     Org = {
				    		 refresh:function(){
				    			 Org.orgTreeShow();
				    		 },
				    		 remove:function(did){
				    			 var options={
											domain:Organization._resource.organization,
											refresh:Org.refresh,
											url:"../../organization/org/"+did,
											button:dijit.byId("btn_org_del"),
											dialogId:"orgDlg",
											resource:Organization._resource
									};
								KppModule.restProxy(options).remove();
				    		 },
				    		 orgId:"",
							 orgTreeShow:function(){
					    			 var xhrArgs = {
					 	    			    url: "../../organization/org/list.json",
					 	    			    handleAs: "text",
					 	    			    load: function(data){
					 	    			    	eval("data="+data);
					 	    			    	
					 	    			    	var store = new dojo.store.Memory({
											        data: data,
											        getChildren: function(object){
											            return this.query({parent: object.id});
											        }
												});
					 	    			    	
					 	    			    	myModel = new dijit.tree.ObjectStoreModel({
					 	    			           store: store,
					 	    			           query: {id: 'root'}
					 	    			       });
					 	    			    	
					 	    			    	tree=dijit.byId("organizationTree");
					 	    			    	if(tree!=null){
					 	    			    		tree.destroy();
					 	    			    		dojo.byId("org_treeContent").innerHTML='<div id="organizationTree"></div>';
					 	    			    	}
														 	    			    	
					 	    			    	menuTree = new dijit.Tree({
					 	    			    		model : myModel,
					 	    			    		showRoot: true,
					 	    			    		openOnClick: false
					 	    			    	}, 'organizationTree');
					 	    			    	menuTree.startup();
					 	    			    	
					 	    			    	var pMenu;
					 	    			        pMenu = new dijit.Menu({
					 	    			            targetNodeIds: ["organizationTree"],
					 	    			           	selector: ".dijitTreeNode",
					 	    			           	style:"display: none;"
					 	    			        });
					 	    			        pMenu.addChild(new dijit.MenuItem({
					 	    			            label:$ksub(KppModule.commonResource.operCreate,[Organization._resource.organization]) ,
					 	    			            iconClass: "icon_s_admin icon_s_admin_org_new",
					 	    			            onClick: function(){
					 	    			            	var tn = dijit.byNode(this.getParent().currentTarget);
					 									var dvId=tn.item.id;
					 									$ku.showDialog({
					 										id:"organization_new",
					 										url:"../../organization/org/"+dvId+"/new.html",
					 										title:$ksub(KppModule.commonResource.operCreate,[Organization._resource.organization]),
					 										resource:Organization._resource,
					 										style:"width:300px;height:190px;"});
					 	    			            }
					 	    			        }));
					 	    			       pMenu.addChild(new dijit.MenuItem({
					 	    			            label:$ksub(KppModule.commonResource.operEdit,[Organization._resource.organization]) ,
					 	    			            iconClass: "icon_s_admin icon_s_admin_org_edit",
					 	    			            onClick: function(){
					 	    			            	var tn = dijit.byNode(this.getParent().currentTarget);
					 									var dvId=tn.item.id;
					 									if(dvId!="root"){
						 									$ku.showDialog({
						 										id:"organization_edit",
						 										url:"../../organization/org/edit/"+dvId+".html",
						 										title:$ksub(KppModule.commonResource.operEdit,[Organization._resource.organization]),
						 										resource:Organization._resourse,
						 										style:"width:300px;height:190px;"});
						 									}
					 	    			            }
					 	    			        }));
					 	    			      pMenu.addChild(new dijit.MenuItem({
					 	    			            label:$ksub(KppModule.commonResource.operDelete,[Organization._resource.organization]),
					 	    			            iconClass: "icon_s_admin icon_s_admin_org_remove",
					 	    			            onClick: function(){
					 	    			            	var tn = dijit.byNode(this.getParent().currentTarget);
					 	                           		var dvId=tn.item.id;
					 									if(dvId!="root"){

					 									this.dlg=dijit.byId("orgDlg");
					 									if(!this.dlg)this.dlg=new dijit.Dialog({
					 										id:"orgDlg",
					 										title: KppModule.commonResource.confirm,
					 										style: "padding:0px;width:300px;height:200px;background-color:#FFF;"});
					 										this.dlg.set("content","<div style=\"padding:20px;text-align:center\">"+KppModule.commonResource.removeOrganizationConfig+"</div>" +
					 										"<div style=\"text-align:center\"><div data-dojo-type=\"dijit.form.Button\" data-dojo-props=\"iconClass:'dijitEditorIcon dijitEditorIconDelete', id:'btn_org_del',showLabel:true, busyLabel:'"+KppModule.commonResource.removing+"'\">"+KppModule.commonResource.remove+
					 										"<script type=\"dojo/method\" event=\"onClick\" args=\"evt\">Org.remove('"+dvId+"')<\/script>"+
					 										"</div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+
					 										"<div data-dojo-type=\"dijit.form.Button\" data-dojo-props=\"iconClass:'dijitEditorIcon dijitEditorIconCancel', showLabel:true\">"+KppModule.commonResource.cancel +
					 										"<script type='dojo/method' event='onClick' args='evt'>dijit.byId('orgDlg').hide();<\/script></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+
					 										"</div>"
					 									);
					 									this.dlg.show();
					 									}
					 	    			            }
					 	    			        }));
					 	    			     	var handle =on(menuTree, "click", function(item, node, evt){
					 	    			     		Org.findOne(item.id);
					 	    			     		dijit.byId("org_memo_title").set("title",Organization._resource.organizationTitle+" &raquo; "+item.name);
					 	    			     	});
					 	    			     	dojo.query(".dijitTreeIcon").removeClass("dijitFolderOpened").addClass("icon_s_admin icon_s_admin_org");
					 	    			    },
					 	    			    error: function(error){
					 	    			    }
					 	    			  };
					 	    		dojo.xhrGet(xhrArgs);
					    		 },
					    	findOne:function(id){
					    		 var xhrArgs = {
					 	    			    url: "../../organization/org/"+id,
					 	    			    handleAs: "text",
					 	    			    load: function(data){
					 	    			    	eval("data="+data);
					 	    			    	dojo.byId("organization_typecode").innerHTML=data.message.code;
					 	    			    	dojo.byId("organization_label").innerHTML=data.message.label;
					 	    			    	if(data.message.activeFlag){
					 	    			    		dojo.byId("org_active").innerHTML="启用";
					 	    			    	}else{
					 	    			    		dojo.byId("org_active").innerHTML="不启用";
					 	    			    	}
					 	    			    }, error: function(error){
					 	    			    }
					    		 };
					    		 dojo.xhrGet(xhrArgs);
					    	} 
				     };
				     Org.orgTreeShow();
				     
				     dojo.byId("lbl_organization_typecode").innerHTML = Organization._resource.organizationCode ;
				     dojo.byId("lbl_organization_label").innerHTML = Organization._resource.organizationlabel;
				     dojo.byId("lbl_org_active").innerHTML = KppModule.commonResource.activeLabel;
				});
				
				$kdom.appendDojoProp("org_memo_title","title",Organization._resource.organizationTitle);
				$kdom.appendDojoProp("cp_org_nav","content","<img class=\"icon_s_admin icon_s_admin_org\" src=\"${pageContext.request.contextPath}/assets/images/blank.gif\" /><span>"+Organization._resource.organization+"</span>");
			</script>
			
<span style="display:none">To solve IE7/8 script event tag problem.</span>
<div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="liveSplitters:true" class="contentWrapper" style="margin:-2px;height:100%">
	<div id="cp_org_nav" data-dojo-type="dijit/layout/ContentPane"  data-dojo-props="region:'top'" class="contentWrapperRight contentPaneNav" style="border:none;margin:-5px;padding:10px 0 10px 10px;background-color:transparent">
		
	</div>
	<div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="region:'left'" style="width:450px;margin: -9px 0px;">
		<div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'"  style="border:none;background-color:transparent;">
			<div data-dojo-type="dijit/form/Button" id="btn_org_refresh" data-dojo-props="iconClass:'dijitCommonIcons dijitIconUndo'"
				onclick="Org.orgTreeShow()" >
			</div>
		</div>
		<div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'center'"  id="org_treeContent" style="background-color:transparent;">
			<div id="organizationTree"></div>
		</div>
		
	</div>
	<div data-dojo-type="dijit/TitlePane" id="org_memo_title" data-dojo-props="region:'center'" style="border:none;background-color:transparent;margin:40px 0px">
		<table width="100%" cellspacing="10">
			<tr>
				<td width="40%"><label id="lbl_organization_typecode">organization type code</label></td>
				<td id="organization_typecode"></td>
			</tr>
			<tr>
				<td width="40%"><label id="lbl_organization_label">organization type label</label></td>
				<td id="organization_label"></td>
			</tr>
			<tr>
				<td width="40%"><label id="lbl_org_active">Active</label></td>
				<td id="org_active"></td>
			</tr>
		</table>
	</div>
</div>
